<?php

require_once 'common.php';

$act = isset($_REQUEST['act']) && !empty($_REQUEST['act']) ? $_REQUEST['act'] : '';

if ($act == 'reg') {
    $adminRow = M('admin')->where('username = "' . $_REQUEST['username'] . '"')->find();
    if (!$_REQUEST['username']) {
        returnJson(1, '用户名不允许为空！');
    } else if (!$_REQUEST['password']) {
        returnJson(1, '密码不允许为空！');
    } else if ($adminRow) {
        returnJson(1, '用户名已存在！');
    } else {
        $adminData = array(
            'username' => $_REQUEST['username'],
            'password' => md5($_REQUEST['password']),
            'admin_role' => $_REQUEST['admin_role'],
            'create_time' => time()
        );
        M('admin')->insert($adminData);
        returnJson(0, '成功');
    }
}

display('reg');